<!-- subpkg_consult/department/index.vue -->
<script lang="ts" setup>
import { departmentListApi } from '@/apis/consult';
import type { DepartData } from '@/types/consult';
import { computed, ref } from 'vue';

defineProps<{
  type: string,
  illnessType: string
}>()

// 1. 获取科室
const depList = ref<DepartData[]>([])
const getDepList = async () => {
  const res = await departmentListApi()
  depList.value = res
  // console.log(depList.value)
}
getDepList()

// 2. 切换选择
const activeIndex = ref(0)
const changeTab = (i: number) => {
  activeIndex.value = i
}

// 3. 获取二级科室
const subDepList = computed(() => depList.value[activeIndex.value]?.child)
</script>

<template>
  <view class="department-page">
    <scroll-view scroll-y class="department-primary">
      <view class="department-item" :class="{ active: activeIndex === index}" v-for="(item, index) in depList"
        :key="item.id" @click="changeTab(index)">{{ item.name }}</view>
    </scroll-view>
    <scroll-view class="department-secondary">
      <navigator v-for="item in subDepList" :key="item.id" hover-class="none"
        :url="`/subpkg_consult/description/index?type=${type}&illnessType=${illnessType}&depId=${item.id}`"
        class="department-item">
        {{ item.name }}
      </navigator>
    </scroll-view>
  </view>
</template>

<style lang="scss">
@import './index.scss';
</style>